﻿<%@ WebHandler Language="C#" Class="RateLog" %>


using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business;
using Chenxin.Lib.Business.BLL;

public class RateLog : AjaxHandlerBase
{

    override public void RequestProcess(HttpContext context)
    {
        try
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";

            string strOp = context.Request["op"];
            string strRet = string.Empty;
            switch (strOp.ToLower())
            {
                case "getlist":
                    GetList(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }


    private void GetList(HttpContext context)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(" 1=1 and isnull(DiscountRate,1)<1 ");
        if (!String.IsNullOrEmpty(context.Request["Addtime"]))
        {
            sb.AppendFormat(" and  {0}>= '{1}'", context.Request["datetype"], context.Request["Addtime"]);
        }
        if (!String.IsNullOrEmpty(context.Request["Endtime"]))
        {
            sb.AppendFormat(" and  {0}< '{1}'", context.Request["datetype"],DateTime.Parse(context.Request["Endtime"].ToString()).AddDays(1));
        }

        if (!String.IsNullOrEmpty(context.Request["keyword"]))
        {
            sb.AppendFormat(" and (ContractCode like '%{0}%' or HouseAddress like '%{0}%')", context.Request["keyword"]);
        }

        //页码
        int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
        //页显示行数
        int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数

        string order = "RateDate desc";
        if (!string.IsNullOrEmpty(context.Request["sort"]))
        {
            order = context.Request["sort"];
        }

        string FieldList = ",ContractId,RateDate,ContractCode,ContractDate,ArchivementDate,HouseAddress,DiscountRate,Depart,Employee,Point";

        string TableFieldList = "ContractId,RateDate,ContractCode,ContractDate,ArchivementDate,HouseAddress,DiscountRate,dbo.f_get_contract_pointallot('Depart',ContractId,'All') as Depart,dbo.f_get_contract_pointallot('Employee',ContractId,'All') as Employee,dbo.f_get_contract_pointallot('Point',ContractId,'All') as Point";

        string TableName = "t_Contract_BaseInfo";

        DataSet ds = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetList(strPageIndex, strPageSize, order, TableName, sb.ToString(), FieldList, TableFieldList, true);

        context.Response.Write(string.Format("{{success:1,msg:'',data:{{count:{0},{1}}}}}", ds.Tables[1].Rows[0][0], Chenxin.Lib.Utility.JsonHelp.Convert2Json(ds.Tables[0])));
    }
}